package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 攻略文章
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class StrategyDetail  extends  BaseDomain{
    public static final Integer STATE_RELEASE=1;
    public static final Integer STATE_NORMAL=2;

    private String title;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone ="GMT+8" )
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone ="GMT+8" )
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;

    private Integer sequence;

    private String coverUrl;

    private Integer state=STATE_NORMAL;

    private StrategyCatalog catalog;
    //设置关联的id
    private Long strategyId;

    //一对一关系
    private StrategyContent content;//sql中先不进行查询

    public String getStateDisplay(){
        if(state==STATE_NORMAL){
            return "待审核";
        }else if(state==STATE_RELEASE){
            return "发布";
        }
        return "";
    }

    public String getJson(){
        Map<String,Object> map =new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("releaseTime",releaseTime);
        map.put("sequence",sequence);
        map.put("strategyId",strategyId);
        map.put("coverUrl",coverUrl);
        map.put("state",state);
        if(catalog!=null){
            map.put("catalogId",catalog.getId());
        }
        return JSONUtils.toJSONString(map);
    }



}